package com.example.jpushdemo;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.widget.TextView;

import com.hq.app.R;

public class MessageActivity extends BaseActivity {
	private TextView tv_message;
	private TweetReceiver tweetReceiver;// 动弹发布接收器

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		// TextView tv = new TextView(this);
		// tv.setText("用户自定义打开的Activity====="+getIntent().getStringExtra("message"));
		// addContentView(tv, new LayoutParams(LayoutParams.FILL_PARENT,
		// LayoutParams.FILL_PARENT));
		setContentView(R.layout.message_activity);
		tv_message = (TextView) findViewById(R.id.tv_message);

		// 注册广播接收器
		tweetReceiver = new TweetReceiver();
		IntentFilter filter = new IntentFilter();
		filter.addAction("net.oschina.app.action.APP_TWEETPUB");
		registerReceiver(tweetReceiver, filter);
	}

	
	@Override
	protected void onDestroy() {
		super.onDestroy();
		unregisterReceiver(tweetReceiver);
	}
	
	/**
	 * 发送广播-发布动弹
	 * 
	 * @param context
	 * @param notice
	 */
	public static void sendBroadCastTweet(Context context, String str_message) {
		if (str_message == null) {
			return;
		}
		Intent intent = new Intent("net.oschina.app.action.APP_TWEETPUB");
		intent.putExtra("message", str_message);
		context.sendBroadcast(intent);
	}

	public class TweetReceiver extends BroadcastReceiver {
		@Override
		public void onReceive(final Context context, Intent intent) {
			tv_message.setText("" + tv_message.getText().toString()
					+ intent.getStringExtra("message"));
		}
	}

}
